package com.rpa.server.servicerpaserver.crawler.controller;

import com.rpa.server.servicerpaserver.crawler.entity.dto.ClazzCrawlerDto;
import com.rpa.server.servicerpaserver.crawler.entity.dto.ScoreDto;
import com.rpa.server.servicerpaserver.crawler.operate.LogonOperate;
import com.rpa.server.servicerpaserver.crawler.operate.ScoreOperate;
import com.rpa.server.servicerpaserver.crawler.operate.StuOperate;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CompletableFuture;

/**
 * @ClassName StuCrawlerController
 * @Description TODO
 * @Author 86152
 * @Date 2025/2/17 21:31
 * @Version 1.0
 **/
@Tag(name = "获取教务信息相关接口", description = "StuCrawlerController")
@Slf4j
@RestController
@RequestMapping("/crawler")
public class StuCrawlerController {
    @Autowired
    private StuOperate stuOperate;
    @Autowired
    private LogonOperate logonOperate;
    @Autowired
    private ScoreOperate scoreOperate;
    @PostMapping("/getStuList")
    @Operation(summary = "获取教务系统学年信息", description = "getStuList")
    public Boolean getStuList(@RequestBody ClazzCrawlerDto crawlerDto){
        CompletableFuture<Boolean> booleanCompletableFuture = logonOperate.logonStu(crawlerDto.getAccountId());
        booleanCompletableFuture.thenAccept(aBoolean -> {
            if (!aBoolean) {
                log.error("登录失败");
            }
            stuOperate.getStu(crawlerDto.getAccountId());
        });
        return null;
    }
    @PostMapping("/submitScore")
    @Operation(summary = "提交成绩", description = "submitScore")
    public Boolean submitScore(@RequestBody ScoreDto scoreDto){
        scoreOperate.submitScore(scoreDto);
        return true;
    }
}
